package svgundoredo;

/**
 * This class is for the paint command
 */
import svgedit.svg.SVGPaint;
import svgedit.svg.SVGStylable;

public class PaintElementCommand extends AbstractCommand
{
    private SVGPaint paint;
    private SVGStylable elem;
    private int type;
    private String newStringColor, oldStringColor;
    
    /**
     * This command to add the paint commnad to the stack
     * 
     * @param elem
     *            current select element
     * @param paint
     *            the new paint
     * @param type
     *            the type whether 1 stroke color or 0 fill color
     */
    public PaintElementCommand(SVGStylable elem, SVGPaint paint, int type)
    {
        this.paint = paint;
        this.elem = elem;
        this.type = type;
        newStringColor = paint.valueAsString();
        if (type == 0)
            oldStringColor = elem.getFill().valueAsString();
        else
            oldStringColor = elem.getStroke().valueAsString();
        
    }
    
    @Override
    public void execute()
    {
        // paint.setRGBColor(newColor);
        paint.setValueFromString(newStringColor);
        if (type == 0)
            elem.getFill().setValueFromPaint(paint);
        else if (type == 1)
            elem.getStroke().setValueFromPaint(paint);
    }
    
    @Override
    public void undo()
    {
        // paint.setRGBColor(oldColor);
        paint.setValueFromString(oldStringColor);
        if (type == 0)
            elem.getFill().setValueFromPaint(paint);
        else if (type == 1)
            elem.getStroke().setValueFromPaint(paint);
        
    }
    
}
